﻿using System;
using SignalR;
using TinyContactManager.Web.Models;

namespace TinyContactManager.Web.Internal.Signaling
{
    public class ContactNotification
    {
        private readonly static Lazy<ContactNotification> LocalInstance = new Lazy<ContactNotification>(() => new ContactNotification());

        public static ContactNotification Instance
        {
            get
            {
                return LocalInstance.Value;
            }
        }

        public void NotifyRefresh(RegistrationModel model)
        {
            var clients = GlobalHost.DependencyResolver.Resolve<IConnectionManager>().GetHubContext<ContactHub>();
            clients.Clients.refresh(model);
        }

        public void NotifyDelete(RegistrationModel model)
        {
            var clients = GlobalHost.DependencyResolver.Resolve<IConnectionManager>().GetHubContext<ContactHub>();
            clients.Clients.remove(model);
        }
    }
}